package com.chhuang.huaao.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;

import com.chhuang.utils.config.SysConfig;
import com.chhuang.utils.httpRequest.HttpClientUtil;
import com.chhuang.utils.httpRequest.ResponseBean;

public class BaiduGeocoderUtil {
	
	public static String reGeocoder(String location) throws ClientProtocolException, IOException{
		List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
		params.add(new BasicNameValuePair("ak",SysConfig.getValue("baiduAK")));
		params.add(new BasicNameValuePair("location",location));
		params.add(new BasicNameValuePair("output","json"));
		params.add(new BasicNameValuePair("pois","0"));
		params.add(new BasicNameValuePair("coordtype","gcj02ll"));
		
		ResponseBean response = HttpClientUtil.post("http://api.map.baidu.com/geocoder/v2/", params, null);
		
		return response.getResult();
	}

	public static void main(String[] args) {
		try {
			String p = reGeocoder("31.494566513272993,119.45626128685248");
			System.out.println(p);
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
